package id.chen;

public class Face {
	private int dimension;
	private char[][] cubeColors;
	private Face north;
	private Face east;
	private Face south;
	private Face west;
	
	public Face(int dimension, char color){
		
		this.dimension=dimension;
		this.cubeColors=new char[dimension][dimension];
		for(int row=0;row<dimension;row++){
			for(int column=0;column<dimension;column++){
				this.cubeColors[row][column]=color;
			}
		
		}
		
		
	}
	

	public void rotate(boolean isClockwise){
		this.setCubeColors(rotateArray(isClockwise,this.getCubeColors()));
	}
	
	public char[][] rotateArray(boolean isClockwise,char[][] array){
		char[][] tempArray=createCopyOf(array);
		for(int row=0;row<dimension;row++){
			for(int column=0;column<dimension;column++){
				if(isClockwise){
					array[row][column]=tempArray[(-column+(dimension*2-1))%dimension][row]; //CW			
				}else{
					array[row][column]=tempArray[column][(-row+(dimension*2-1))%dimension]; //CCW
				}

			}
		}
		return array;
	}
	
	public void setRow(boolean notReversed, Face face, char[] row, int rowNo){
		char[][] array=face.getCubeColors();
		
		if(notReversed){
			array[rowNo]=row;
		}else{
			for(int i=0;i<dimension;i++){
				array[rowNo][-i+dimension-1]=row[i];
			}
		}
		
		face.setCubeColors(array);
	}
	
	public void setCol(boolean notReversed, Face face, char[] col, int colNo){
		char[][] array=face.getCubeColors();
		if(notReversed){
			for(int i=0;i<dimension;i++){
				array[i][colNo]=col[i];
			}
		}else{
			for(int i=0;i<dimension;i++){
				array[-i+dimension-1][colNo]=col[i];
			}
		}
		
		face.setCubeColors(array);
	}
	
	
	
	public char[][] createCopyOf(char[][] array){
		char[][] tempArray=new char[dimension][dimension];
		for(int row=0;row<dimension;row++){
			for(int column=0;column<dimension;column++){
				tempArray[row][column]=cubeColors[row][column];
			}
		}
		return tempArray;
	}
	
	
	public char[][] getCubeColors() {
		return cubeColors;
	}
	public void setCubeColors(char[][] face) {
		this.cubeColors = face;
	}
	public int getDimension() {
		return dimension;
	}
	public void setDimension(int dimension) {
		this.dimension = dimension;
	}

	public Face getNorth() {
		return north;
	}


	public void setNorth(Face north) {
		this.north = north;
	}


	public Face getEast() {
		return east;
	}


	public void setEast(Face east) {
		this.east = east;
	}


	public Face getSouth() {
		return south;
	}


	public void setSouth(Face south) {
		this.south = south;
	}


	public Face getWest() {
		return west;
	}


	public void setWest(Face west) {
		this.west = west;
	}
	
}
